local gulve = fk.CreateSkill {
  name = "lvshi__gulve&",
  mode_skill = true,
}

Fk:loadTranslationTable{
  ["lvshi__gulve&"] = "固略",
  [":lvshi__gulve&"] = "出牌阶段开始时，你可观看一名角色的身份牌和手牌。回合技，当你成为非先驱角色使用【杀】的目标后，你摸一张牌。",
  ["#lvshi__gulve-target"] = "固略：你可观看一名角色的身份牌和手牌",
}

local U = require "packages/utility/utility"

gulve:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(gulve.name) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player),
      min_num = 1,
      max_num = 1,
      skill_name = gulve.name,
      prompt = "#lvshi__gulve-target",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {to = to[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).to
    room:addTableMark(player, "lvshi__gulve", to.id)
    if not to:isKongcheng() then
      room:viewCards(player, {
        cards = to:getCardIds("h"),
        skill_name = gulve.name,
      })
    end
  end,
})

gulve:addEffect(fk.TargetConfirmed, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(gulve.name) and data.firstTarget and data.card.trueName == "slash"
    and player.room:getTag("prophet") ~= data.from.id and player:usedEffectTimes(gulve.name) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = gulve.name})
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, gulve.name)
  end,
})

gulve:addEffect("visibility", {
  role_visible = function (self, player, target)
    if table.contains(player:getTableMark("lvshi__gulve"), target.id) then
      return true
    end
  end,
})

return gulve
